package com.xdy.redis.demo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Author: XDY.
 * @Email: 2280944114@qq.com
 * @CreateTime: 2023-05-07  16:00
 * @Description: TODO
 * @Version: 1.0
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket docket(Environment environment){
        //设置开启swagger的环境
        Profiles profiles = Profiles.of("dev", "test");
        //得到是否满足环境要求
        boolean isEnable = environment.acceptsProfiles(profiles);
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("RedisTemplate测试")
                .apiInfo(apiInfo())
                .enable(isEnable)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.xdy.redis.demo.controller"))//扫描接口的包
                .paths(PathSelectors.ant("/redis/**"))//只扫描/redis开头的api
                .build();
    }
    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("RedisTemplate测试文档")
                .description("学习redis7")
                .version("1.0")
                //团队信息
                .termsOfServiceUrl("http://xlk.web3v.work")
                .license("XLK777")
                .licenseUrl("https://www.xlk777.top")
                //个人联系方式
                .contact(new Contact("许琳康","http://xlk.web3v.work","2280944114@qq.com"))
                .build();
    }
}
